<template>
	<view style="display: flex;flex-direction: column;justify-content: center;min-height: 100vh;background-color: #ffa271;padding-left: 20px;padding-right: 20px;">
		<view style="border-radius: 6px 6px 0pt 0pt;display: flex;justify-content: space-between;background-color: #fff;height: 120px;padding-left: 10px;padding-right: 10px;margin-top: -20px;">
			<view style="margin-top: auto;margin-bottom: auto;">
				卡密:
			</view>
			<view style="margin-top: auto;margin-bottom: auto;">
				<u--input
				    placeholder="请输入卡密"
				    border="surround"
				    v-model="kami_text"
				  ></u--input>
			</view>
			<view style="margin-top: auto;margin-bottom: auto;">
			    <view style="border: 1px solid #ffa271;border-radius: 50px;color: #ffa271;padding: 5px 15px;font-size: 14px;height: 20px;" @click="duihuan()">
			    	兑换
			    </view>
			</view>
		</view>
		<view style="display: flex;justify-content: space-between;overflow: hidden;margin-top: -15rpx;">
			<view style="background: #ffa271;border-radius: 50%;height: 30rpx;margin-left: -15rpx;width: 30rpx;z-index: 20;"></view>
			<view style="background: #ffa271;border-radius: 50%;height: 30rpx;margin-right: -15rpx;width: 30rpx;z-index: 20;"></view>
		</view>
		<view style="border-radius: 0pt 0pt 6px 6px;background-color: #fff6f2;margin-top: -15rpx;padding-top: 15px;padding-bottom: 15px;padding-left: 15px;font-size: 13px;color: #cf9d83;" @click="goLink()">
			卡密购买：{{kami_url}}
		</view>
	</view>
</template>

<script>
	import w_md5 from "../../../js_sdk/zww-md5/w_md5.js"
	export default {
		components: {
		    w_md5
		},
		data() {
			return {
				app_key: '',
				kami_text: '',
				kami_url: '' //卡密购买链接
			}
		},
		onLoad() {
			this.getCardurl()
		},
		methods: {
			getCardurl(){
				uni.request({
					url: getApp().globalData.websiteUrl + "/index.php/appv1/kxapps/cardurl",
					success: (res) => {
						console.log(res.data)
						this.kami_url = res.data.url
					}
				})
			},
			goLink(){
				plus.runtime.openURL(this.kami_url)
			},
			duihuan(){
				if(this.kami_text==''){
					uni.showToast({
						icon:"none",
						title:"卡密不能为空"
					})
					return;
				}
				var time = new Date().getTime()
				this.app_key = getApp().globalData.websiteKey
				
				var param = "card=" + this.kami_text + "&deviceid=" + getApp().globalData.deviceid + "&facility=" + getApp().globalData.facility + "&timestamp=" + time + "&user_id=" + uni.getStorageSync('user').uid + "&user_token=" + uni.getStorageSync('user').utoken
				
				var sign = w_md5.hex_md5_32Upper(param + this.app_key)
				uni.request({
				    url: getApp().globalData.websiteUrl + '/index.php/appv1/kxapps/kami?' + param + "&sign=" + sign,
					success: (res) => {
						console.log(res.data)
						if(res.data.code!==1){
							uni.showToast({
								icon:"error",
								title:res.data.msg
							})
						}else{
							uni.showToast({
								icon:"success",
								title:res.data.msg
							})
						}
				    }
				});
			},
		}
	}
</script>

<style>

</style>
